import React from 'react';
import { Form, Input, Button, Space } from 'antd';

interface StudentSearchProps {
  onSearch: (values: any) => void;
  onReset: () => void;
}

const StudentSearch: React.FC<StudentSearchProps> = ({ onSearch, onReset }) => {
  const [form] = Form.useForm();

  const handleSearch = (values: any) => {
    // 确保空字符串和undefined都被过滤掉
    const filteredValues = Object.fromEntries(
      Object.entries(values).filter(([_, value]) => value !== '' && value !== undefined)
    );
    onSearch(filteredValues);
  };

  const handleReset = () => {
    form.resetFields();
    onReset();
  };

  return (
    <Form form={form} layout="inline" onFinish={handleSearch}>
      <Form.Item name="username" label="姓名">
        <Input placeholder="请输入" allowClear />
      </Form.Item>
     
      <Form.Item>
        <Space>
          <Button type="primary" htmlType="submit">
            查询
          </Button>
          <Button onClick={handleReset}>
            重置
          </Button>
        </Space>
      </Form.Item>
    </Form>
  );
};

export default StudentSearch;